1 /*
2 * Copyright (C) 2007 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.common.base;
18
19 import com.google.common.annotations.GwtCompatible;
20 import com.google.common.annotations.GwtIncompatible;
21
22 import java.nio.charset.Charset;
23
24 /**
25 * Contains constant definitions for the six standard {@link Charset} instances, which are
26 * guaranteed to be supported by all Java platform implementations.
27 *
28 * <p>Assuming you're free to choose, note that <b>{@link #UTF_8} is widely preferred</b>.
29 *
30 * <p>See the Guava User Guide article on <a
31 * href="http://code.google.com/p/guava-libraries/wiki/StringsExplained#Charsets">
32 * {@code Charsets}</a>.
33 *
34 * @author Mike Bostock
35 * @since 1.0
36 */
37 @GwtCompatible(emulated = true)
38 public final class Charsets {
39 private Charsets() {}
40
41 /**
42 * US-ASCII: seven-bit ASCII, the Basic Latin block of the Unicode character set (ISO646-US).
43 *
44 * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
45 * {@link java.nio.charset.StandardCharsets#US_ASCII} instead.
46 *
47 */
48 @GwtIncompatible("Non-UTF-8 Charset")
49 public static final Charset US_ASCII = Charset.forName("US-ASCII");
50
51 /**
52 * ISO-8859-1: ISO Latin Alphabet Number 1 (ISO-LATIN-1).
53 *
54 * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
55 * {@link java.nio.charset.StandardCharsets#ISO_8859_1} instead.
56 *
57 */
58 @GwtIncompatible("Non-UTF-8 Charset")
59 public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
60
61 /**
62 * UTF-8: eight-bit UCS Transformation Format.
63 *
64 * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
65 * {@link java.nio.charset.StandardCharsets#UTF_8} instead.
66 *
67 */
68 public static final Charset UTF_8 = Charset.forName("UTF-8");
69
70 /**
71 * UTF-16BE: sixteen-bit UCS Transformation Format, big-endian byte order.
72 *
73 * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
74 * {@link java.nio.charset.StandardCharsets#UTF_16BE} instead.
75 *
76 */
77 @GwtIncompatible("Non-UTF-8 Charset")
78 public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
79
80 /**
81 * UTF-16LE: sixteen-bit UCS Transformation Format, little-endian byte order.
82 *
83 * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
84 * {@link java.nio.charset.StandardCharsets#UTF_16LE} instead.
85 *
86 */
87 @GwtIncompatible("Non-UTF-8 Charset")
88 public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
89
90 /**
91 * UTF-16: sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order
92 * mark.
93 *
94 * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
95 * {@link java.nio.charset.StandardCharsets#UTF_16} instead.
96 *
97 */
98 @GwtIncompatible("Non-UTF-8 Charset")
99 public static final Charset UTF_16 = Charset.forName("UTF-16");
100
101 /*
102 * Please do not add new Charset references to this class, unless those character encodings are
103 * part of the set required to be supported by all Java platform implementations! Any Charsets
104 * initialized here may cause unexpected delays when this class is loaded. See the Charset
105 * Javadocs for the list of built-in character encodings.
106 */
107 }